<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 回调地狱
        // setTimeout(() => {
        //     console.log(111);
        //     setTimeout(() => {
        //         console.log(222);
        //         setTimeout(() => {
        //             console.log(333);
        //         }, 3000);
        //     }, 2000);
        // }, 1000);


        //使用生成器完成
        function One(){
            setTimeout(()=>{
                console.log(111);
                iterator.next();
            },1000)
        }

        function Two(){
            setTimeout(()=>{
                console.log(222);
                iterator.next();
            },2000)
        }
        function Three(){
            setTimeout(()=>{
                console.log(333);
                iterator.next();
            },3000)
        }

        function *gen(){
            yield One();
            yield Two();
            yield Three();
        }

        let iterator  = gen();
        console.log(iterator.next());
    </script>
</body>
</html>